<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Constructs the object from a BSON array or document</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.mongodb-bson-unserializable.html">« MongoDB\BSON\Unserializable</a></li>
      <li style="float: right;"><a href="class.mongodb-bson-binaryinterface.html">MongoDB\BSON\BinaryInterface »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.mongodb-bson-unserializable.html">MongoDB\BSON\Unserializable</a></li>
    <li>Constructs the object from a BSON array or document</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mongodb-bson-unserializable.bsonunserialize" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDB\BSON\Unserializable::bsonUnserialize</h1>
  <p class="verinfo">(mongodb &gt;=1.0.0)</p><p class="refpurpose"><span class="refname">MongoDB\BSON\Unserializable::bsonUnserialize</span> &mdash; <span class="dc-title">Constructs the object from a BSON array or document</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongodb-bson-unserializable.bsonunserialize-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><strong>MongoDB\BSON\Unserializable::bsonUnserialize</strong></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$data</code></span>): <span class="type"><span class="type void">void</span></span></div>

  <p class="para rdfs-comment">
   Called during unserialization of the object from BSON. The properties of the
   BSON array or document will be passed to the method as an <span class="type">array</span>.
  </p>
  <p class="para">
   Remember to check for an <span class="property">_id</span> property when handling data
   from a BSON document.
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    This method acts as the
    <a href="language.oop5.decon.html#language.oop5.decon.constructor" class="link">constructor</a> of the
    object. The <a href="language.oop5.decon.html#object.construct" class="link">__construct()</a> method
    will <em class="emphasis">not</em> be called after this method.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-mongodb-bson-unserializable.bsonunserialize-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">data</code> (<span class="type">array</span>)</dt>

    <dd>

     <p class="para">
      Properties within the BSON array or document.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongodb-bson-unserializable.bsonunserialize-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The return value from this method is ignored.
  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-mongodb-bson-unserializable.bsonunserialize-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1401">
   <p><strong>示例 #1 <span class="function"><strong>MongoDB\BSON\Unserializable::bsonUnserialize()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">MyDocument&nbsp;</span><span style="color: #007700">implements&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">BSON</span><span style="color: #007700">\</span><span style="color: #0000BB">Unserializable<br /></span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;</span><span style="color: #0000BB">$data&nbsp;</span><span style="color: #007700">=&nbsp;[];<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">bsonUnserialize</span><span style="color: #007700">(array&nbsp;</span><span style="color: #0000BB">$data</span><span style="color: #007700">):&nbsp;</span><span style="color: #0000BB">void<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$data</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">$bson&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">BSON</span><span style="color: #007700">\</span><span style="color: #0000BB">fromJSON</span><span style="color: #007700">(</span><span style="color: #DD0000">'{&nbsp;"foo":&nbsp;"bar"&nbsp;}'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$value&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">BSON</span><span style="color: #007700">\</span><span style="color: #0000BB">toPHP</span><span style="color: #007700">(</span><span style="color: #0000BB">$bson</span><span style="color: #007700">,&nbsp;[</span><span style="color: #DD0000">'root'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'MyDocument'</span><span style="color: #007700">]);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$value</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
object(MyDocument)#1 (1) {
  [&quot;data&quot;:&quot;MyDocument&quot;:private]=&gt;
  array(1) {
    [&quot;foo&quot;]=&gt;
    string(3) &quot;bar&quot;
  }
}
</pre></div>
   </div>
  </div>
 </div>



 <div class="refsect1 seealso" id="refsect1-mongodb-bson-unserializable.bsonunserialize-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="mongodb-bson-serializable.bsonserialize.html" class="function" rel="rdfs-seeAlso">MongoDB\BSON\Serializable::bsonSerialize()</a> - Provides an array or document to serialize as BSON</span></li>
   <li class="member"><span class="interfacename"><a href="class.mongodb-bson-persistable.html" class="interfacename">MongoDB\BSON\Persistable</a></span></li>
   <li class="member"><a href="mongodb.persistence.html" class="xref">Persisting Data</a></li>
  </ul>
 </div>


</div></div></div></body></html>